# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Zach Bacon <zachbacon@vba-m.com>

_realname=gpgme
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.15.1
pkgrel=2
pkgdesc="A C wrapper library for GnuPG (mingw-w64)"
arch=('any')
url="https://gnupg.org/related_software/gpgme/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnupg"
         "${MINGW_PACKAGE_PREFIX}-libassuan"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error"
         "${MINGW_PACKAGE_PREFIX}-npth")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-qt5"
             "doxygen")
options=('!emptydirs') # '!strip' 'debug')
source=("https://www.gnupg.org/ftp/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2"{,.sig}
        0004-gpgme-find-gnupg.patch
        0005-invoke-scripts-via-sh.patch
        0006-fix-building-docs.patch
        0007-mkdefsinc-use-CPPFLAGS.patch
        0008-no-py2.patch
        relocatable-cmake.patch
        gpgmepp-portable-types.patch
        gpgme-fix-cpp-tests.patch)
#These might be signed by any of these keys https://gnupg.org/signature_key.html
validpgpkeys=('D8692123C4065DEA5E0F3AB5249B39D24F25E3B6'
              '031EC2536E580D8EA286A9F22071B08A33BD3F06'
              '5B80C5754298F0CB55D8ED6ABCEF7E294B092E28'
              '6DAA6E64A76D2840571B4902528897B826403ADA')
sha256sums=('eebc3c1b27f1c8979896ff361ba9bb4778b508b2496c2fc10e3775a40b1de1ad'
            'SKIP'
            '71763a209761afe6495d3d85e25bbe6ba76348450d426f8a2618a34a264e058a'
            '2389cc237bf860b961bf3519377e83f7678e657dcf28c33510cd155f80516d42'
            'b56fe3e3da872ca84d08b4aa426e6f71b3227e2a253bc45bf6023abf1288ecc9'
            '393c89dfc707a4982ab297196b00b5b7e1b8af7ee5bfc02846800c5ca3608891'
            'd421cd1a4cdd7a011954c60cbc80e68b42b7fd014f1685aabd33217f3bd23de3'
            '32465eb5f99015d06a0b89c30c69a7c4208ab32c287275b729cf9bec08c4474c'
            '0a98bbfeff6643aa7195b3f5c87feab9ea8b329adfb65c2339e72f4fbb98523c'
            'd09070c005b72e8aed14a848553f7c7289353ff7f32e62c9013a729ba46d7117')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0004-gpgme-find-gnupg.patch
  patch -p1 -i "${srcdir}"/0005-invoke-scripts-via-sh.patch
  patch -p1 -i "${srcdir}"/0006-fix-building-docs.patch
  patch -p1 -i "${srcdir}"/0007-mkdefsinc-use-CPPFLAGS.patch
  patch -p1 -i "${srcdir}"/0008-no-py2.patch
  patch -p1 -i "${srcdir}"/relocatable-cmake.patch
  patch -p1 -i "${srcdir}"/gpgmepp-portable-types.patch
  patch -p1 -i "${srcdir}"/gpgme-fix-cpp-tests.patch

  autoreconf -ivf
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  # mingw doxygen can't wrok with UNIX paths in doxyfile
  DOXYGEN=/usr/bin/doxygen \
  PYTHON=${MINGW_PREFIX}/bin/python3 \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --libexecdir=${MINGW_PREFIX}/bin \
    --disable-fd-passing \
    --enable-shared \
    --enable-static \
    --disable-gpgsm-test \
    --enable-w32-glib

  make
}

check() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  #make check
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
